import type { Dict } from "@/api/dict/types";
import { getDictList } from "@/api/dict";
import { ref } from "vue";


/**
 * 
 * 
 * @param types 
 */
export const useDict = (...types: string[]) => {

    const dict = ref<any>({})

    const getDict = async (type: string) => {
        dict.value[type] = await getDictList(type)
    }

    const showDictName = (type: string, value: string) => {
        return dict.value[type]?.find((item: Dict) => item.value == value).name
    }

    types.forEach((type: string) => getDict(type))

    return { dict ,showDictName}
}